﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AppSocketModel;
using AppSocketService.SendTimes;
using AppSocketService.SleepTime;
using BCGPSCommon;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BCGPSRESTful.Controllers.Page.Command
{
    /// <summary>
    /// 给GSP设备发命令 设置唤醒后数据发送次数
    /// </summary>
    [ApiExplorerSettings(GroupName = "DeviceCmd")]
    [Route("api/[controller]")]
    [ApiController]
    public class SendTimesController : PageBaseController
    {
        ISendTimesHistoryService  sendTimesHistoryService;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sendTimesHistoryService"></param>
        public SendTimesController(ISendTimesHistoryService sendTimesHistoryService)
        {
            this.sendTimesHistoryService = sendTimesHistoryService;
        }


        /// <summary>
        /// 给GSP设备发设置唤醒后数据发送次数命令 
        /// </summary>
        /// <param name="imei">设备IMEI</param>
        /// <param name="value">数据发送次数</param>
        /// <returns></returns>
        [ProducesResponseType(typeof(bool), 200)]
        [HttpGet("[action]")]
        public ActionResult<bool> SetCmd(string imei, int value)
        {
            return sendTimesHistoryService.SetCmd(imei, value);
        }


        /// <summary>
        /// 查询历史记录
        /// </summary>
        /// <param name="imei"></param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="desc">倒序</param>
        /// <param name="index">页码</param>
        /// <param name="size">记录数</param>
        /// <returns></returns>
        [ProducesResponseType(typeof(PageableList<SendTimesDto>), 200)]
        [HttpGet("[action]")]
        public ActionResult<PageableList<SendTimesDto>> Query(string imei, DateTime start, DateTime end, bool? desc = false, int? index = 0, int? size = 20)
        {
            return sendTimesHistoryService.GetList(imei, start, end, desc.Value, index.Value, size.Value);
        }
    }
}